package com.siashan.unipay4j.ali;

import com.siashan.unipay4j.biz.PayBizConfiguration;
import com.siashan.unipay4j.biz.PayBizProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * 支付宝支付自动配置类
 *
 * @author  siashan
 * @since v1.0.1
 **/
@Configuration
@EnableConfigurationProperties(AliPayProperties.class)
@Import(PayBizConfiguration.class)
public class AliPayAutoConfiguration {

    @Autowired
    private PayBizProperties payBizProperties;

    @Bean
    @ConditionalOnMissingBean
    public AliPayProperties aliPayProperties() {
        return new AliPayProperties();
    }


    @Bean
    @ConditionalOnMissingBean
    public AliPayFactoryProvider aliPayFactoryProvider(AliPayProperties aliPayProperties,AliPayFactory aliPayFactory){
        return new AliPayFactoryProvider(aliPayProperties,aliPayFactory,payBizProperties);
    }

    @Bean
    @ConditionalOnMissingBean
    public AliPayFactory aliPayFactory(){
        return  new AliPayFactory();
    }
}
